// ============================== 导入依赖 ============================== //

import { MessageBox } from 'element-ui'

// ============================== 导出提交 ============================== //

export default {
  /**
   * 配置
   */
  CONFIG: {
    PROMPT: {},
    INFO: {},
    SUCCESS: {},
    ERROR: {},
    WARNING: {},
  },

  /**
   * 提交 await CORE.PROMPT.prompt()
   */
  prompt(message, title = '提交', options = {}) {
    return new Promise((resolve) => {
      MessageBox.prompt(message, title, { ...this.CONFIG.PROMPT, ...options })
        .then(({ value }) => resolve(value))
        .catch((e) => e)
    })
  },

  /**
   * 消息 await CORE.PROMPT.info()
   */
  info(message, title = '消息', options = {}) {
    return new Promise((resolve) => {
      MessageBox.prompt(message, title, { ...this.CONFIG.INFO, ...options, type: 'info' })
        .then(({ value }) => resolve(value))
        .catch((e) => e)
    })
  },

  /**
   * 成功 await CORE.PROMPT.success()
   */
  success(message, title = '成功', options = {}) {
    return new Promise((resolve) => {
      MessageBox.prompt(message, title, { ...this.CONFIG.SUCCESS, ...options, type: 'success' })
        .then(({ value }) => resolve(value))
        .catch((e) => e)
    })
  },

  /**
   * 失败 await CORE.PROMPT.error()
   */
  error(message, title = '失败', options = {}) {
    return new Promise((resolve) => {
      MessageBox.prompt(message, title, { ...this.CONFIG.ERROR, ...options, type: 'error' })
        .then(({ value }) => resolve(value))
        .catch((e) => e)
    })
  },

  /**
   * 警告 await CORE.PROMPT.warning()
   */
  warning(message, title = '警告', options = {}) {
    return new Promise((resolve) => {
      MessageBox.prompt(message, title, { ...this.CONFIG.WARNING, ...options, type: 'warning' })
        .then(({ value }) => resolve(value))
        .catch((e) => e)
    })
  },
}
